/**
 * @projectName study_java
 * @package Prototype
 * @className Prototype.Test
 */
package Prototype;

import java.util.ArrayList;

/**
 * Test
 * @description 测试类
 * @author answer_wx
 * @date 2022/6/27 11:15
 * @version 1.0
 */
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        ConcretePrototype c1 = new ConcretePrototype("测试", 29, "男");
        ArrayList<String> list = new ArrayList<>();
        list.add("工作经历1");
        list.add("工作经历2");
        list.add("工作经历3");
        c1.setJobs(list);
        System.out.println("------引用赋值-----，也会改变");
        Prototype c4 = c1;
        c4.setName("引用地址");
        list.add("工作经历引用赋值");
        System.out.println("c1=======" + c1.toString());
        System.out.println("c4=======" + c4.toString());
        System.out.println("------浅拷贝-----,修改引用类型List，其他对象的jobs都会变");
        c1.setName("浅拷贝");
        Prototype shallowClone1 = c1.shallowClone();
        Prototype shallowClone2 = c1.shallowClone();
        shallowClone2.setName("clone 2 号");
        list.remove(1);
        Prototype shallowClone3 = c1.shallowClone();
        shallowClone3.setSex("女");
        list.add("浅拷贝02");
        System.out.println("c1=======" + c1.toString());
        System.out.println("shallowClone1=======" + shallowClone1.toString());
        System.out.println("shallowClone2=======" + shallowClone2.toString());
        System.out.println("shallowClone3=======" + shallowClone3.toString());
        System.out.println("------深拷贝------,修改List不影响其他对象");
        c1.setName("深拷贝");
        Prototype deepClone1 = c1.deepClone();
        list.set(list.size() - 1, "深拷贝01");
        System.out.println("c1=======" + c1.toString());
        System.out.println("deepClone1=======" + deepClone1.toString());

    }
}